﻿using System;
using System.Windows.Forms;
using Interfaces.Delete_Interfaces;
using Interfaces.Information_Interfaces;
using Repository;
using Model.Domain_Model;
using Presenters.Inherited_Presenters;

namespace Presenters.Delete_Presenters
{
    public class ClientDeletePresenter:OperationStatus
    {
        IClientDeleteView view = null;
        IDb database = Repo.GetDatabaseInstance();
        public Client client = null;

        public ClientDeletePresenter(IClientDeleteView view)
        {
            this.view = view;
        }

        public void ExitApp()
        {
            view.Close();
        }

        /// <summary>
        /// Usuwa klienta - obiekty typu Client, Roads, Valuations, Email, Phones z bazy danych
        /// </summary>
        public void Delete()
        {
            nameOperation = "Usuwanie klienta";
            try
            {
                database.Clients.DeleteClient(client);
                view.ShowSuccess();
                view.Close();
            }
            catch (Exception ex)
            {
                exception = ex.Message;
                view.ShowError();
            }
        }
    }
}
